package com.kuaiditu.assistant.api.yd_api;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunda.crypt.EDOutputData;
import com.yunda.crypt.NativeEncryption;


/**
 * Created by Eenie on 2017/8/28.
 * Email: eeniework@gmail.com
 * Des:
 */

public class YDBaseResponse {
    private Boolean success;
    private Long req_time;
    private String body;
    private String errorcode;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Long getReq_time() {
        return req_time;
    }

    public void setReq_time(Long req_time) {
        this.req_time = req_time;
    }

    public String getBody() {

        return body;
    }


    public String getDecodeBody() {
        EDOutputData edData = new EDOutputData();
        String res = getBody();
        NativeEncryption.JNI_IDecrypt(res, edData);

        if (TextUtils.isEmpty(edData.GetData())) {
            return res;
        }

        return edData.GetData();
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getErrorcode() {
        return errorcode;
    }

    public void setErrorcode(String errorcode) {
        this.errorcode = errorcode;
    }
//
//    public JSONObject getEntity() {
//        return JSON.parseObject(getBody());
//    }
//
//
//    public Object getEntity(Class clz) {
//
//
//        return JSON.parseObject(getBody(), clz);
//    }

    public Object getDeEntity(Class clz) {

        return JSON.parseObject(getDecodeBody(), clz);
    }

    public JSONObject getDeEntity() {

        String body = getDecodeBody();
//        LogUtil.e(body);

        return JSON.parseObject(body);
    }


    private boolean needDecode() {


        return true;
    }


}
